﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Globalization;

namespace KgUtils.Wpf.Converters
{
    [ValueConversion(typeof(object), typeof(bool))]
    public class IsNullToBooleanConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value == null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null || (value.GetType() == typeof(bool) && (bool)value == true))
                return null;
            else
                return value;
        }

        #endregion
    }
}
